package com.jtny.nytb.equipment.service.impl;

import cn.hutool.core.collection.CollUtil;

import com.jtny.nytb.equipment.dto.instrument.QueryInstrumentDTO;

import com.jtny.nytb.equipment.dto.instrument.ResponseInstrumentDTO;
import com.jtny.nytb.equipment.service.InstrumentService;
import com.jtny.nytb.equipment.service.InstrumentExtraService;
import com.jtny.nytb.equipment.vo.instrument.*;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author 智慧能源中心-伍天宇
 * @version 1.0
 * @package com.jtny
 * @fileName InstrumentBizImpl.java
 * @createTime 2024年01月11日 13:19
 * @Copyright© 2024 jtny
 * 江投能源技术研究院 版权所有
 */
@Service
@AllArgsConstructor
public class InstrumentExtraServiceImpl implements InstrumentExtraService {

    private InstrumentService instrumentClient;


    /**
     * 获取计量器具信息
     *
     * @param nameList 名称列表
     * @return {@link Map}<{@link String}, {@link ResponseInstrumentDTO}>
     */
    @Override
    public Map<String, ResponseInstrumentDTO> mapInstrumentByNameList(List<String> nameList) {
        if (CollUtil.isEmpty(nameList)) {
            return new HashMap<>();
        }
        QueryInstrumentDTO queryInstrumentDTO = new QueryInstrumentDTO();
        queryInstrumentDTO.setInstrumentNameList(nameList);
        List<ResponseInstrumentDTO> result = instrumentClient.listInstrument(queryInstrumentDTO);
        return result.stream().collect(Collectors.toMap(ResponseInstrumentDTO::getInstrumentName, instrument -> instrument));
    }

}

